package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.annos.OperateLog;
import com.tbit.uqbike.constant.MapConstant;
import com.tbit.common.constant.MethodEnum;
import com.tbit.common.constant.ModuleEnum;
import com.tbit.uqbike.object.pojo.ParkPointVert;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.base.CalibrateService;
import com.tbit.uqbike.service.business.ParkPointVertService;
import com.tbit.uqbike.webmanager.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chen
 * @Description: 垂直定位配置
 * @Date: 创建于 10:50 2020/8/14
 */
@RestController
@RequestMapping("/vert")
public class ParkPointVertController {
    @Autowired
    private ParkPointVertService parkPointVertService;
    @Autowired
    private CalibrateService calibrateService;

    /**
     * 通过站点id获取
     *
     * @param parkPointId
     * @param mapType
     * @return
     */
    @RequestMapping("/getByParkPointId")
    public JsonResult getByParkPointId(Integer parkPointId, @RequestParam(defaultValue = "2") Integer mapType) {
        Assert.notNull(parkPointId, "ver.parkPointId.notNull");
        ParkPointVert parkPointVert = parkPointVertService.getByParkPointId(parkPointId);
        if (parkPointVert != null) {
            /**经纬度校准*/
            calibrateService.calVert(parkPointVert, MapConstant.MAP_ORI, mapType);
        }
        return JsonResult.ok(parkPointVert);
    }

    /**
     * 添加
     *
     * @param parkPointVert
     * @return
     */
    @RequestMapping("/insert")
    @OperateLog(module = ModuleEnum.VERTICALPARKING, methods = MethodEnum.VERTICALPARKING_ADD)
    public JsonResult insert(ParkPointVert parkPointVert, @RequestParam(defaultValue = "2") Integer mapType) {
        Assert.notNull(parkPointVert.getParkPointId(), "ver.parkPointId.notNull");
        Assert.notNull(parkPointVert.getPoints(), "ver.points.notNull");
        //经纬度校验
        calibrateService.calVert(parkPointVert, mapType, MapConstant.MAP_ORI);
        parkPointVertService.insert(parkPointVert);
        return JsonResult.ok();
    }

    /**
     * 修改
     *
     * @param parkPointVert
     * @return
     */
    @RequestMapping("/edit")
    @OperateLog(module = ModuleEnum.VERTICALPARKING, methods = MethodEnum.VERTICALPARKING_UPDATE)
    public JsonResult edit(ParkPointVert parkPointVert, @RequestParam(defaultValue = "2") Integer mapType) {
        Assert.notNull(parkPointVert.getParkPointId(), "ver.parkPointId.notNull");
        Assert.notNull(parkPointVert.getPoints(), "ver.points.notNull");
        //经纬度校验
        calibrateService.calVert(parkPointVert, mapType, MapConstant.MAP_ORI);
        parkPointVertService.edit(parkPointVert);
        return JsonResult.ok();
    }

}
